package model;

public class ChronoTrigger implements Runnable{
	private tickedsNode tickList;
	private boolean go;
	
	public ChronoTrigger(){
		go = true;
		(new Thread(this)).start();
	}
	
	private class tickedsNode{
		Ticked curTicked;
		tickedsNode nextNode;
	}
	
	public boolean addTicked(Ticked t)
	{
		//adds new Ticked to beginning of the tickList
		tickedsNode nextHead = new tickedsNode();
		nextHead.curTicked = t;
		nextHead.nextNode = tickList;
		tickList = nextHead;
		
		return(true);
	}

	public void stop()
	{
		go = false;
	}
	
	@Override
	public void run() {
		while(go)
		{
			//cycles through all Tickeds in tickList every 0.1 seconds until stop is called
			tickedsNode curSpot = tickList;
			while(curSpot != null)
			{
				curSpot.curTicked.tick();
				curSpot = curSpot.nextNode;
			}
			try
			{
				Thread.sleep(100);
			}catch(InterruptedException ie)
			{
				
			}
		}
	}
}
